﻿using _8Group.MES.ISongService.WmBarCode;
using _8Group.MES.ISongService.WmBarCode.DTO;
using _8Group.MES.ISongService.WMProductRecpt;
using _8Group.MES.Model.WM仓储管理;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace _8Group.MES.SongService
{
    [ApiExplorerSettings(GroupName = "宋恒漳")]
    public class WmBarCodeService : ApplicationService, IWmBarCodeService
    {
        private readonly IRepository<WM_bar_code, int> _barCodeRepository;
        public WmBarCodeService(IRepository<WM_bar_code, int> barCodeRepository)
        {
            _barCodeRepository = barCodeRepository;
        }

        /// <summary>
        /// 获取条码信息
        /// </summary>
        /// <param name="barCodeDTO"></param>
        /// <returns></returns>
        public async Task<object> GetWmBarCodeAsync(RequestWmBarCodeDTO barCodeDTO)
        {
            var wmBarCodeList = await _barCodeRepository.GetQueryableAsync();
            wmBarCodeList = wmBarCodeList.WhereIf(barCodeDTO.BarcodeType != null, x => x.BarcodeType.Contains(barCodeDTO.BarcodeType));
            wmBarCodeList = wmBarCodeList.WhereIf(barCodeDTO.BussinessName != null, x => x.BussinessName.Contains(barCodeDTO.BussinessName));
            wmBarCodeList = wmBarCodeList.WhereIf(barCodeDTO.BussinessCode != null, x => x.BussinessCode.Contains(barCodeDTO.BussinessCode));
            var count = wmBarCodeList.Count();
            wmBarCodeList = wmBarCodeList.OrderBy(x => x.Id).Skip(((barCodeDTO.Page - 1) ?? 0) * (barCodeDTO.Limit ?? 10)).Take(barCodeDTO.Limit ?? 10);
            var result = new ResponseModel
            {
                code = "",
                count = count,
                data = wmBarCodeList.ToList(),
                msg = "",
            };
            return result;
        }
    }
}
